﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpMap.Utilities;
using CCSUser;
using CCSSysSetting;
using CCSDocument;
using SharpMap.Utilities;


namespace CCSMain
{
    public partial class CCSMainForm : Form
    {
        private int childFormNumber = 0;
        public SplashForm m_frmSplashForm;
        private User m_pUser;

        public User LoginUser
        {
            get
            {
                return m_pUser;
            }

            set
            {
                m_pUser = value;
            }
        }


        /// <summary>
        /// 初始化菜单命令
        /// </summary>
        public void InitializeMenu()
        {

            ToolStripMenuItem TempToolStripMenuItem1;
            ToolStripMenuItem TempToolStripMenuItem2;
          
            BaseCommand MenuCommand;

            //ResourceManager rm = new ResourceManager("RAPDCF.Resource1", Assembly.GetExecutingAssembly());

            //switch (enumPropertyType)
            //{
            //    //初始化基本菜单
            //    case PropertyType.Null:

            this.menuStrip.Items.Clear();
            TempToolStripMenuItem1 = new ToolStripMenuItem();
            //添加文件菜单项
            TempToolStripMenuItem1.Text = "系统设置";
            this.menuStrip.Items.Add(TempToolStripMenuItem1);

            if (m_pUser.HasFunction("A"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new DepartmentSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("B"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new RoleSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }
          
            if (m_pUser.HasFunction("C"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new EmployeeSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("O"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new EmployeeDepartmentSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("J"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CompanyRoleSettingcmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("D"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new ProjectSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("E"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new BonusSettingCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("F"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new UserAdminCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("G"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new UserGroupAdminCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            TempToolStripMenuItem1 = new ToolStripMenuItem();
            //添加文件菜单项
            TempToolStripMenuItem1.Text = "文档操作";
            this.menuStrip.Items.Add(TempToolStripMenuItem1);


            if (m_pUser.HasFunction("H"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new InputDocumentCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("I"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new ImportDocumentCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            //添加报表分析菜单项
            TempToolStripMenuItem1 = new ToolStripMenuItem();
            TempToolStripMenuItem1.Text = "报表分析";
            this.menuStrip.Items.Add(TempToolStripMenuItem1);


            if (m_pUser.HasFunction("Y"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionAgeProjectCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("N"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionAgeCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("Z"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionReceivableProjectCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

           
            if (m_pUser.HasFunction("K"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionReceivableCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("a"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.ExternalCommisionCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("P"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.PersonalCommisionCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("b"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.SalesPersonCommisionCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }



            if (m_pUser.HasFunction("L"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionReceivedCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }



            if (m_pUser.HasFunction("d"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionReceivedDetailCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("M"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.CommisionCountedCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("e"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.DocRoleCommisionCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("f"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.ProjectRoleCommisionCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("g"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.SalesPersonListCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }

            if (m_pUser.HasFunction("h"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.ReferralListCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }


            if (m_pUser.HasFunction("i"))
            {
                TempToolStripMenuItem2 = new ToolStripMenuItem();
                MenuCommand = new CCSReport.ProjectAreaPriceCmd();
                MenuCommand.OnCreate(this);
                MenuCommand.User = m_pUser;
                TempToolStripMenuItem2.Text = MenuCommand.Caption;
                TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
                TempToolStripMenuItem2.Tag = MenuCommand;
                TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
            }




            ////添加语言设置菜单项
            //TempToolStripMenuItem2 = new ToolStripMenuItem();
            //TempToolStripMenuItem2.Text = rm.GetString("Menu1.2");
            //TempToolStripMenuItem2.Click += new EventHandler(TempToolStripMenuItem2_Click);
            //MenuCommand = new LanguageSettings();
            //TempToolStripMenuItem2.Tag = MenuCommand;
            //TempToolStripMenuItem1.DropDownItems.Add(TempToolStripMenuItem2);
     




                //    break;
                //case PropertyType.Apartment:

                //    break;

            //}

        }

        void TempToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            ((BaseCommand)((ToolStripMenuItem)sender).Tag).OnClick();
        }


        public CCSMainForm()
        {
            InitializeComponent();
          
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            // 创建此子窗体的一个新实例。
            Form childForm = new Form();
            // 在显示该窗体前使其成为此 MDI 窗体的子窗体。
            childForm.MdiParent = this;
            childForm.Text = "窗口" + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
                // TODO: 在此处添加打开文件的代码。
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
                // TODO: 在此处添加代码，将窗体的当前内容保存到一个文件中。
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: 使用 System.Windows.Forms.Clipboard 将所选的文本或图像插入到剪贴板
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: 使用 System.Windows.Forms.Clipboard 将所选的文本或图像插入到剪贴板
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: 使用 System.Windows.Forms.Clipboard.GetText() 或 System.Windows.Forms.GetData 从剪贴板中检索信息。
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void CCSMainForm_Load(object sender, EventArgs e)
        {
            InitializeMenu();
        }

        private void CCSMainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
